var KOC = require("koc.common.utils");
var QueryString = require("querystring");

var StateData = require("../statedata");
var DALFactory = require("../../lib/dal/dal-factory");
var CommonUtils = require("../../lib/common-utils");

module.exports = {
  ////////////////////////////////////////////
  //首页
  ////////////////////////////////////////////
  Index: function (req, res, callback) {
    var _PageData = {
      flag: 0,
      message: ""
    };
    _PageData.Commodity = CommonUtils.Anchor.Tags;
    //首页推荐数据
    DALFactory.RedisCommon.UserAnchorListHot.Get(0, 24, function (retValue) {
      if (retValue.hasError) {
        res.jsonp({flag: retValue.errorCode, msg: retValue.message});
        return;
      }
      //过滤 艺人数据
      retValue.returnObject.forEach(function (Value, Key) {
        retValue.returnObject[Key] = {
          User_ID: Value.User_ID,
          NickName: Value.NickName,
          Account_City: Value.Account_City,
          Anchor_Level: Value.Anchor_Level,
          Hot_Value: Value.Hot_Value,
          Live: Value.Live,
          Live_IsMobile: Value.Live_IsMobile,
          Live_StartTime: Value.Live_StartTime,
          RoomTitle: Value.RoomTitle
        };
      });
      _PageData.HotAnchor = {flag: 0, msg: "", data: retValue.returnObject};
      CommonUtils.Common.PageScript_PageData(res, _PageData);
      res.locals.Title = "全民秀网-美女视频-互动娱乐平台";
      res.render("index", callback);
    });
  },
  ////////////////////////////////////////////
  //流量分配页
  ////////////////////////////////////////////
  Channel: function (req, res) {
    DALFactory.Business.Report_ChannelStrategy({
      Channel_ID: KOC.StringUtils.ToString(req.params.clId) || KOC.StringUtils.ToString(req.params._cid),
      Room_ID: KOC.StringUtils.ToIntPositive(req.params._roomid),
      UV: StateData.Cookie.UVID.Get(req, res),
      IP: KOC.StringUtils.GetClientIP(req)
    }, function (retValue) {
      res.redirect(retValue.returnObject);
    });
  },
  ////////////////////////////////////////////
  //房间
  ////////////////////////////////////////////
  Room: function (req, res, callback) {
    var _UserState = StateData.Value(req, res);
    var _PageData = {
      flag: 0,
      message: ""
    };
    _PageData.RoomID = req.params.id;
    if (!_PageData.RoomID && _UserState.IsLogin && _UserState.IsAnchor) {
      res.redirect("/room/" + _UserState.User_ID);
      return;
    }
    var _RoomTemplate = "";
    //读取艺人信息
    DALFactory.Business.User_AnchorInfo(_PageData.RoomID, function (retValue) {
      if (retValue.hasError) {
        _PageData.flag = retValue.errorCode;
        _PageData.message = retValue.message;
      } else {
        _RoomTemplate = retValue.returnObject.RoomTemplate;
        _PageData.Commodity = CommonUtils.Commodity;
        _PageData.Game = {Lottery: CommonUtils.Lottery};
      }
      switch (_RoomTemplate) {
        default:
          _RoomTemplate = "default";
          break;
      }
      CommonUtils.Common.PageScript_PageData(res, _PageData);
      res.render("room/" + _RoomTemplate, callback);
    });
  },
  RoomMobile: function (req, res, callback) {
    var _UserState = StateData.Value(req, res);
    var _PageData = {
      flag: 0,
      message: ""
    };
    _PageData.RoomID = req.params.id;
    if (!_PageData.RoomID && _UserState.IsLogin && _UserState.IsAnchor) {
      res.redirect("/room/" + _UserState.User_ID);
      return;
    }
    _PageData.Commodity = CommonUtils.Commodity;
    _PageData.Game = {Lottery: CommonUtils.Lottery};
    CommonUtils.Common.PageScript_PageData(res, _PageData);
    res.render("room/mobile", callback);
  },
  ////////////////////////////////////////////
  //排行榜
  ////////////////////////////////////////////
  Rank: function (req, res, callback) {
    var _UserState = StateData.Value(req, res);
    var _PageData = {
      flag: 0,
      message: ""
    };
    res.locals.Title = "排行榜";
    _PageData.Commodity = CommonUtils.Commodity;
    res.render("rank/index", callback);
  },
  ////////////////////////////////////////////
  //商城
  ////////////////////////////////////////////
  Mall: function (req, res, callback) {
    var _UserState = StateData.Value(req, res);
    var _PageData = {
      flag: 0,
      message: ""
    };
    res.locals.Title = "商城";
    switch (req.params.type) {
      case "vip":
        res.locals.Title = "会员";
        _PageData.VIPList = CommonUtils.Commodity.VIP.Data;
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("mall/vip", callback);
        return;
      case "motoring":
        res.locals.Title = "座驾";
        _PageData.MountsList = KOC.Lodash.filter(CommonUtils.Commodity.Mounts.Data, {Mall: true});
        //将坐骑经验转换成等级名称
        for (var index in _PageData.MountsList) {
          var UserLevel = _PageData.MountsList[index].UserLevel;
          _PageData.MountsList[index].Level_Name = CommonUtils.User.Level.fnExp(UserLevel).Name;
        }
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("mall/motoring", callback);
        return;
      case "guard":
        res.locals.Title = "守护";
        res.render("mall/guard", callback);
        return;
      default:
        _PageData.VIPList = CommonUtils.Commodity.VIP.Data;
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("mall/vip", callback);
    }
  },
  ////////////////////////////////////////////
  //支付
  ////////////////////////////////////////////
  Pay: function (req, res, callback) {
    var _UserState = StateData.Value(req, res);
    var _PageData = {
      flag: 0,
      message: ""
    };
    res.locals.Title = "支付";
    _PageData.Commodity = CommonUtils.Commodity;
    res.render("pay/index", callback);
  },
  ////////////////////////////////////////////
  //申请入驻
  ////////////////////////////////////////////
  Entry: {
    Index: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      var _PageData = {
        flag: 0,
        message: ""
      };
      res.locals.Title = "申请入驻";
      KOC.Async.series([
        // 判断艺人
        function (callback) {
          DALFactory.User.User_Anchor.Info(_UserState.User_ID, function (retValue) {
            if (retValue) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && retValue.returnObject.Status == 2) {
              retValue.hasError = true;
              retValue.errorCode = 2;
              retValue.message = "你申请的艺人申请中。。请耐心等待";
              callback(retValue);
              return;
            }
            callback()
          });
        },
        //判断公会
        function (callback) {
          DALFactory.User.User_Family.Info(_UserState.User_ID, function (retValue) {
            if (retValue) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && retValue.returnObject.Status == 2) {
              retValue.hasError = true;
              retValue.errorCodes = 2;
              retValue.msge = "你申请的公会申请中。。请耐心等待";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          _PageData.flag = retValue.errorCode;
          _PageData.message = retValue.message;
          _PageData.fflag = retValue.errorCodes;
          _PageData.msge = retValue.msge;
        }
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("entry/index", callback);
      });
      return;
    },
    Anchor: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      var _PageData = {
        flag: 0,
        message: ""
      };
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      res.locals.Title = "艺人申请";
      DALFactory.User.User_Anchor.Info(_UserState.User_ID, function (retValue) {
        if (retValue.hasError) {
          _PageData.flag = retValue.errorCode;
          _PageData.message = retValue.message;
        } else if (retValue.returnObject && retValue.returnObject.Status == 2) {
          _PageData.flag = 2;
          _PageData.message = "你申请的艺人申请中。。请耐心等待！";
        }
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("entry/anchor/anchor_agreement", callback);
      });
      return;
    },
    Family: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      var _PageData = {
        flag: 0,
        message: ""
      };
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      res.locals.Title = "公会申请";
      DALFactory.User.User_Family.Info(_UserState.User_ID, function (retValue) {
        if (retValue.hasError) {
          _PageData.flag = retValue.errorCode;
          _PageData.message = retValue.message;
        } else if (retValue.returnObject && retValue.returnObject.Status == 1) {
          _PageData.flag = 1;
          _PageData.message = "你申请的公会申请中。。请耐心等待！";
        }
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("entry/family/family_agreement", callback);
      });
      return;
    },
    ////////////////////////////////////////////
    //艺人申请入驻
    ////////////////////////////////////////////
    Anchor_Service: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      switch (req.params.step) {
        case "step_1":
          res.locals.Title = "艺人申请入驻";
          KOC.Async.series([
            // 申请
            function (callback) {
              DALFactory.User.User_Anchor.Info(_UserState.User_ID, function (retValue) {
                if (retValue.hasError) {
                  callback(retValue);
                  return;
                }
                if (retValue.returnObject && retValue.returnObject.Status == 0) {
                  retValue.hasError = true;
                  retValue.errorCode = 2;
                  retValue.message = "用户已经是艺人";
                  callback(retValue);
                  return;
                }
                if (retValue.returnObject && retValue.returnObject.Status == 1) {
                  retValue.hasError = true;
                  retValue.errorCode = 2;
                  retValue.message = "用户被锁定";
                  callback(retValue);
                  return;
                }
                if (retValue.returnObject && retValue.returnObject.Status == 2) {
                  retValue.hasError = true;
                  retValue.errorCode = 2;
                  retValue.message = "艺人申请中。。请耐心等待";
                  callback(retValue);
                  return;
                }
                callback()
              });
            },
            //用户基本信息
            function (callback) {
              DALFactory.User.User_Info.Info(_UserState.User_ID, function (retValue) {
                if (retValue.hasError) {
                  callback(retValue);
                  return;
                }
                if (!retValue.returnObject) {
                  _PageData.flag = retValue.errorCode;
                  _PageData.message = retValue.message;
                  callback(retValue);
                  return;
                }
                _PageData.UserInfo = {
                  Sex: retValue.returnObject.Sex,
                  Email: retValue.returnObject.Email,
                  Phone: retValue.returnObject.Phone
                };
                callback();
              });
            }
          ], function (retValue) {
            if (retValue) {
              _PageData.flag = retValue.errorCode;
              _PageData.message = retValue.message;
            } else {
              _PageData.Tags = CommonUtils.Anchor.Tags;
            }
            CommonUtils.Common.PageScript_PageData(res, _PageData);
            res.render("entry/anchor/anchor_step_1", callback);
          });
          return;
        case "step_2":
          res.locals.Title = "艺人申请入驻";
          DALFactory.User.User_Anchor.Info(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              _PageData.flag = retValue.errorCode;
              _PageData.message = retValue.message;
            } else if (retValue.returnObject && retValue.returnObject.Status == 2) {
              _PageData.flag = 2;
              _PageData.message = "你申请的艺人申请中。。请耐心等待！";
            }
            _PageData.Banks = CommonUtils.User.Banks;
            CommonUtils.Common.PageScript_PageData(res, _PageData);
            res.render("entry/anchor/anchor_step_2", callback);
          });
          return;
        case "step_3":
          res.locals.Title = "艺人申请入驻";
          DALFactory.User.User_Anchor.Info(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              _PageData.flag = retValue.errorCode;
              _PageData.message = retValue.message;
            } else if (retValue.returnObject && retValue.returnObject.Status == 2) {
              _PageData.flag = 2;
              _PageData.message = "你申请的艺人申请中。。请耐心等待！";
            }
            CommonUtils.Common.PageScript_PageData(res, _PageData);
            res.render("entry/anchor/anchor_step_3", callback);
          });
          return;
        case "step_4":
          res.locals.Title = "艺人申请入驻";
          DALFactory.User.User_Anchor.Info(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              _PageData.flag = retValue.errorCode;
              _PageData.message = retValue.message;
            } else if (retValue.returnObject && retValue.returnObject.Status == 1) {
              _PageData.flag = 1;
              _PageData.message = "你已经申请了艺人，无需申请了";
            } else if (retValue.returnObject && retValue.returnObject.Status == 2) {
              _PageData.flag = 2;
              _PageData.message = "你申请的艺人申请中。。请耐心等待！";
            }
            CommonUtils.Common.PageScript_PageData(res, _PageData);
            res.render("entry/anchor/anchor_step_4", callback);
          });
          return;
        default:
          res.render("entry/anchor/anchor_agreement", callback);
      }
    },
    ////////////////////////////////////////////
    //公会申请入驻
    ////////////////////////////////////////////
    Family_Service: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      switch (req.params.step) {
        case "step_1":
          res.locals.Title = "公会申请入驻";
          DALFactory.User.Family_Info.Info_UserID(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              _PageData.flag = retValue.errorCode;
              _PageData.message = retValue.message;
            } else if (retValue.returnObject && retValue.returnObject.Status == 2) {
              _PageData.flag = 2;
              _PageData.message = "公会申请中。。请耐心等待！";
            }
            CommonUtils.Common.PageScript_PageData(res, _PageData);
            res.render("entry/family/family_step_1", callback);
          });
          return;
        case "step_2":
          res.locals.Title = "公会申请入驻";
          KOC.Async.series([
            // 申请
            function (callback) {
              DALFactory.User.Family_Info.Info_UserID(_UserState.User_ID, function (retValue) {
                if (retValue.hasError) {
                  callback(retValue);
                  return;
                }
                if (retValue.returnObject && retValue.returnObject.Status == 2) {
                  retValue.hasError = true;
                  retValue.errorCode = 2;
                  retValue.message = "你申请的公会申请中。。请耐心等待";
                  callback(retValue);
                  return;
                }
                callback();
              });
            },
            //用户基本信息
            function (callback) {
              DALFactory.User.User_Info.Info(_UserState.User_ID, function (retValue) {
                if (retValue.hasError) {
                  callback(retValue);
                  return;
                }
                if (!retValue.returnObject) {
                  _PageData.flag = retValue.errorCode;
                  _PageData.message = retValue.message;
                  callback(retValue);
                  return;
                }
                _PageData.UserInfo = {
                  Email: retValue.returnObject.Email,
                  Phone: retValue.returnObject.Phone
                };
                callback();
              });
            }
          ], function (retValue) {
            if (retValue) {
              _PageData.flag = retValue.errorCode;
              _PageData.message = retValue.message;
            } else {
              _PageData.Tags = CommonUtils.Anchor.Tags;
            }
            CommonUtils.Common.PageScript_PageData(res, _PageData);
            res.render("entry/family/family_step_2", callback);
          });
          return;
        case "step_3":
          res.locals.Title = "公会申请入驻";
          DALFactory.User.Family_Info.Info_UserID(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              _PageData.flag = retValue.errorCode;
              _PageData.message = retValue.message;
            } else if (retValue.returnObject && retValue.returnObject.Status == 2) {
              _PageData.flag = 2;
              _PageData.message = "公会申请中。。请耐心等待！";
            }
            _PageData.Banks = CommonUtils.User.Banks;
            CommonUtils.Common.PageScript_PageData(res, _PageData);
            res.render("entry/family/family_step_3", callback);
          });

          return;
        case "step_4":
          res.locals.Title = "公会申请入驻";
          DALFactory.User.Family_Info.Info_UserID(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              _PageData.flag = retValue.errorCode;
              _PageData.message = retValue.message;
            } else if (retValue.returnObject && retValue.returnObject.Status == 2) {
              _PageData.flag = 2;
              _PageData.message = "公会申请中。。请耐心等待！";
            }
            CommonUtils.Common.PageScript_PageData(res, _PageData);
            res.render("entry/family/family_step_5", callback);
          });
          return;
        default:
          res.render("/", callback);
      }
    }
  },
  ////////////////////////////////////////////
  //用户中心
  ////////////////////////////////////////////
  Member: function (req, res, callback) {
    var _UserState = StateData.Value(req, res);
    var _PageData = {
      flag: 0,
      message: ""
    };
    if (!_UserState.IsLogin) {
      res.redirect("/");
      return;
    }
    res.locals.Title = "用户中心";
    res.render("member/user/follow", callback);
  },
  Member_User: {
    Follow: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      res.render("member/user/follow", callback);
    },
    Fans: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      res.render("member/user/fans", callback);
    },
    Base_Info: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      var _PageData = {
        flag: 0,
        message: ""
      };
      DALFactory.User.User_Info.Info(_UserState.User_ID, function (retValue) {
        if (retValue.hasError) {
          _PageData.flag = retValue.errorCode;
          _PageData.message = retValue.message;
        } else if (!retValue.returnObject) {
          _PageData.flag = -1;
          _PageData.message = '没有相应参数';
        } else {
          _PageData.UserInfo = {};
          _PageData.UserInfo.Sex = retValue.returnObject.Sex;
          if (retValue.returnObject.Birthday) {
            _PageData.UserInfo.Birthday = moment(retValue.returnObject.Birthday).format('YYYY-MM-DD');
          } else {
            _PageData.UserInfo.Birthday = null;
          }
        }
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("member/user/base_info", callback);
      });
    },
    MyMounts: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      var _PageData = {
        flag: 0,
        message: ""
      };
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      KOC.Async.series([
        // 座驾列表
        function (callback) {
          DALFactory.User.User_Mounts.List(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              _PageData.flag = retValue.errorCode;
              _PageData.message = retValue.message;
              callback(retValue);
              return;
            }
            _PageData.MountsList = retValue.returnObject;
            if (_PageData.MountsList.length > 0) {
              for (var i in _PageData.MountsList) {
                _PageData.MountsList[i].Mounts_ExpireDay = KOC.Moment(_PageData.MountsList[i].Mounts_Expire).diff(KOC.Moment(), "days") < 0 ? 0 : KOC.Moment(_PageData.MountsList[i].Mounts_Expire).diff(KOC.Moment(), "days");
              }
            }
            callback();
          });
        },
        //用户基本信息-使用座驾Id
        function (callback) {
          DALFactory.User.User_Info.Info(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              _PageData.flag = retValue.errorCode;
              _PageData.message = retValue.message;
              callback(retValue);
              return;
            }
            _PageData.Mounts_ID = retValue.returnObject.Mounts_ID;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          _PageData.flag = retValue.errorCode;
          _PageData.message = retValue.message;
        }
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("member/user/my_mounts", callback);
      });


    },
    MyVIP: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      DALFactory.User.User_Info.Info(_UserState.User_ID, function (retValue) {
        if (retValue.hasError) {
          _PageData.flag = retValue.errorCode;
          _PageData.message = retValue.message;
        } else if (!retValue.returnObject) {
          _PageData.flag = retValue.errorCode;
          _PageData.message = retValue.message;
          _PageData.UserInfo = {};
        } else {
          _PageData.UserInfo = {};
          _PageData.UserInfo.VIP = retValue.returnObject.VIP;
          _PageData.UserInfo.VIP_Expire = retValue.returnObject.VIP_Expire;
          _PageData.UserInfo.VIP_ExpireDay = retValue.returnObject.VIP_ExpireDay;
        }
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("member/user/my_vip", callback);
      });
    },
    Pay_records: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      res.render("member/user/pay_records", callback);
    },
    Security: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      DALFactory.User.User_Info.Info(_UserState.User_ID, function (retValue) {
        if (retValue.hasError) {
          _PageData.flag = retValue.errorCode;
          _PageData.message = retValue.message;
        } else if (!retValue.returnObject) {
          _PageData.flag = retValue.errorCode;
          _PageData.message = retValue.message;
        } else {
          _PageData.UserInfo = {};
          _PageData.UserInfo.OAuth_QQ_ID = retValue.returnObject.OAuth_QQ_ID;
          _PageData.UserInfo.OAuth_Weibo_ID = retValue.returnObject.OAuth_Weibo_ID;
          _PageData.UserInfo.OAuth_Weixin_ID = retValue.returnObject.OAuth_Weixin_ID;
          _PageData.UserInfo.Email = retValue.returnObject.Email;
          _PageData.UserInfo.Phone = retValue.returnObject.Phone;
        }
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("member/user/security", callback);
      });

    },
    Consumption: function (req, res, callback) {
      res.render("member/user/consumption", callback);
    },
    Invite: function (req, res, callback) {
      res.render("member/user/user-invite", callback);
    },
    //临时方法
    Channel_Manage: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      if (_UserState.User_ID != 27004) {
        res.redirect("/");
        return;
      }
      res.render("member/user/channel-manage", callback);
    }
  },
  Member_Anchor: {
    ////////////////////////////////////////////
    //艺人收入
    ////////////////////////////////////////////
    Anchor: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      if (!_UserState.IsAnchor) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: "",
        Beans: 0,
        Family_ID: null,
        Settlement: 1
      };
      res.locals.Title = "我是艺人";
      KOC.Async.series([
        function (callback) {
          DALFactory.User.User_Info.Info(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.errorCode = -1;
              retValue.message = "没有相应参数";
              callback(retValue);
              return;
            }
            _PageData.Beans = retValue.returnObject.Beans;
            callback();
          });
        },
        function (callback) {
          DALFactory.User.User_Anchor.Info(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.errorCode = -2;
              retValue.message = "没有相关艺人";
              callback(retValue);
              return;
            }
            _PageData.Family_ID = retValue.returnObject.Family_ID;
            callback();
          });
        },
        function (callback) {
          if (!_PageData.Family_ID) {
            callback();
            return;
          }
          DALFactory.User.Family_Info.Info(_PageData.Family_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.errorCode = -3;
              retValue.message = "没有相关参数";
              callback(retValue);
              return;
            }
            _PageData.Settlement = retValue.returnObject.Settlement;
            callback();
          });
        },
        //临时方法
        function (callback) {
          DALFactory.Report.Anchor_Month.Info({
            User_ID: _UserState.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.errorCode = -3;
              retValue.message = "没有相关数据";
              callback(retValue);
              return;
            }
            _PageData.Beans_Anchor = retValue.returnObject.Beans_Anchor;
            _PageData.Beans_Anchor_Task = retValue.returnObject.Beans_Anchor_Task;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          _PageData.flag = retValue.errorCode;
          _PageData.msg = retValue.message;
        }
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("member/anchor/index", callback);
      });
    },
    ////////////////////////////////////////////
    //艺人基本工资
    ////////////////////////////////////////////
    Anchor_Salary: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      if (!_UserState.IsAnchor) {
        res.redirect("/");
        return;
      }
      res.locals.Title = "艺人基本工资";
      res.render("member/anchor/salary", callback);
    },
    ////////////////////////////////////////////
    //艺人礼物数据
    ////////////////////////////////////////////
    Anchor_Gift: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      if (!_UserState.IsAnchor) {
        res.redirect("/");
        return;
      }
      res.locals.Title = "礼物数据";
      res.render("member/anchor/gift_data", callback);
    },
    ////////////////////////////////////////////
    //艺人直播数据
    ////////////////////////////////////////////
    Anchor_Live: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      if (!_UserState.IsAnchor) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      res.locals.Title = "直播数据";
      KOC.Async.series([
        //艺人总时长
        function (callback) {
          DALFactory.User.User_Anchor.Info(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              _PageData.flag = retValue.errorCode;
              _PageData.message = retValue.message;
              callback(retValue);
              return;
            }
            _PageData.Live_Duration_Total = retValue.returnObject.Live_Duration_Total;
            callback();
          });
        },
        //艺人直播时长和开播时间
        function (callback) {
          DALFactory.User.User_Anchor.Info_Live_Day(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户信息不存在";
              callback(retValue);
              return;
            }
            _PageData.Duration = retValue.returnObject.Duration;
            _PageData.Create_Date = retValue.returnObject.Create_Date;
            callback();
          });
        },
        //实时有效直播时长
        function (callback) {
          DALFactory.User.User_Anchor.Info_Duration_Efftive(_UserState.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              _PageData.flag = retValue.errorCode;
              _PageData.message = retValue.message;
              callback(retValue);
              return;
            }
            _PageData.Live_Duration_Efftive = retValue.returnObject.Live_Duration_Efftive;
            _PageData.Live_Count = retValue.returnObject.Live_Count;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          _PageData.flag = retValue.errorCode;
          _PageData.message = retValue.message;
        }
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("member/anchor/live_data", callback);
      });
    }
  },
  Member_Family: {
    ////////////////////////////////////////////
    //公会收入
    ////////////////////////////////////////////
    Income: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      if (!_UserState.IsFamily) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      res.locals.Title = "公会收入";
      DALFactory.User.Family_Info.Info_UserID(_UserState.User_ID, function (retValue) {
        if (retValue.hasError) {
          res.jsonp({flag: retValue.errorCode, msg: retValue.message});
          return;
        }
        if (!retValue.returnObject) {
          res.jsonp({flag: -3, msg: "没有该公会"});
          return;
        }
        _PageData.Family_ID = retValue.returnObject.Family_ID;
        _PageData.Beans = retValue.returnObject.Beans;
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("member/family/income", callback);
      });
    },
    ////////////////////////////////////////////
    //公会艺人
    ////////////////////////////////////////////
    Anchor: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      if (!_UserState.IsFamily) {
        res.redirect("/");
        return;
      }
      res.locals.Title = "公会艺人";
      DALFactory.User.Family_Info.Info_UserID(_UserState.User_ID, function (retValue) {
        if (retValue.hasError || !retValue.returnObject) {
          _PageData.flag = retValue.errorCode;
          _PageData.message = retValue.message;
        } else {
          _PageData.Family_ID = retValue.returnObject.Family_ID;
        }
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("member/family/anchor", callback);
      });

    },
    ////////////////////////////////////////////
    //公会艺人收入
    ////////////////////////////////////////////
    AnchorIncome: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      if (!_UserState.IsFamily) {
        res.redirect("/");
        return;
      }
      res.locals.Title = "公会艺人收入";
      res.render("member/family/anchor_income", callback);
    },
    ////////////////////////////////////////////
    //公会艺人基本工资
    ////////////////////////////////////////////
    AnchorSalary: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      if (!_UserState.IsFamily) {
        res.redirect("/");
        return;
      }
      res.locals.Title = "艺人基本工资";
      res.render("member/family/anchor_salary", callback);
    },
    ////////////////////////////////////////////
    //公会艺人直播数据
    ////////////////////////////////////////////
    AnchorLive: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      if (!_UserState.IsFamily) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      res.locals.Title = "直播数据";
      DALFactory.User.Family_Info.Info_UserID(_UserState.User_ID, function (retValue) {
        if (retValue.hasError || !retValue.returnObject) {
          _PageData.flag = retValue.errorCode;
          _PageData.message = retValue.message;
        } else {
          _PageData.Family_ID = retValue.returnObject.Family_ID;
        }
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("member/family/anchor_live", callback);
      });
    },
    ////////////////////////////////////////////
    //公会收入详细数据
    ////////////////////////////////////////////
    Income_Detail: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      if (!_UserState.IsFamily) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      res.locals.Title = "公会收入明细";
      CommonUtils.Common.PageScript_PageData(res, _PageData);
      res.render("member/family/anchor_income_detail", callback);
    }
  },
  User: {
    My: {
      Init: function (req, res, callback) {
        var _UserState = StateData.Value(req, res);
        var _PageData = {
          flag: 0,
          message: ""
        };
        if (!_UserState.IsLogin) {
          res.redirect("/");
          return;
        }
        res.locals.Title = "用户中心";
        res.render("user/main", callback);
      },
    }
  },


  ////////////////////////////////////////////
  //搜索
  ////////////////////////////////////////////
  Search: function (req, res, callback) {

    var _UserState = StateData.Value(req, res);
    var _PageData = {
      flag: 0,
      message: ""
    };
    res.locals.Title = "搜索";
    _PageData.value = req.params.key;
    CommonUtils.Common.PageScript_PageData(res, _PageData);
    res.render("search/index", callback);
  },
  ////////////////////////////////////////////
  //帮助中心
  ////////////////////////////////////////////
  Help: function (req, res, callback) {
    res.locals.Title = "帮助";
    var _PageData = {
      flag: 0,
      message: "",
      id: req.params.id
    };
    CommonUtils.Common.PageScript_PageData(res, _PageData);
    if (req.params.id) {
      res.render("help/" + _PageData.id, callback);
    } else {
      res.render("help/help-1-1", callback);
    }

  },
  Agreement: {
    ////////////////////////////////////////////
    //虚拟社区币协议
    ////////////////////////////////////////////
    Coin: function (req, res, callback) {
      res.locals.Title = "全民秀网虚拟社区币服务协议";
      res.render("agreement/coin", callback);
    },
    ////////////////////////////////////////////
    //用户协议
    ////////////////////////////////////////////
    User: function (req, res, callback) {
      res.locals.Title = "用户注册协议";
      res.render("agreement/user", callback);
    }
  },
  Order: {
    Gift: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };

      res.render("member/user/consumption-gift", callback);
    },
    Gifts: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      res.render("member/user/consumption-gifts", callback);
    },
    Guard: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      res.render("member/user/consumption-guard", callback);
    },
    Vip: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      res.render("member/user/consumption-vip", callback);
    },
    Mounts: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      res.render("member/user/consumption-mounts", callback);
    },
    Winning: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("/");
        return;
      }
      var _PageData = {
        flag: 0,
        message: ""
      };
      res.render("member/user/consumption-winning", callback);
    }
  },
  ////////////////////////////////////////////
  //第三方登录返回
  ////////////////////////////////////////////
  Oauth: {
    Success: function (req, res, callback) {
      res.locals.Title = "用户登录授权成功";
      res.render("login/oauth/success", callback);
    }
  },
  ////////////////////////////////////////////
  //App
  ////////////////////////////////////////////
  App: {
    Download: {
      Mobile: function (req, res) {
        res.locals.Title = "APP下载-青春秀，看全民秀!";
        res.render("app/download/m/index");
      },
      Pc: function (req, res, callback) {
        res.locals.Title = "青春秀，看全民秀!";
        res.render("app/download/pc/index", callback);
      }
    }
  },
  ////////////////////////////////////////////
  //忘记密码
  ////////////////////////////////////////////
  Forget: function (req, res, callback) {
    var _UserState = StateData.Value(req, res);
    if (_UserState.IsLogin) {
      res.redirect("/");
      return;
    }
    var _PageData = {
      flag: 0,
      message: ""
    };
    switch (req.params.step) {
      case "step1":
        res.locals.Title = "找回密码";
        res.render("safe/forget/step1", callback);
        break;
      case "step2":
        res.locals.Title = "找回密码";
        _PageData.Phone = req.params.Phone;
        CommonUtils.Common.PageScript_PageData(res, _PageData);
        res.render("safe/forget/step2", callback);
        break;
      case "step3":
        res.locals.Title = "找回密码成功";
        res.render("safe/forget/step3", callback);
        break;
      default:
        res.render("safe/forget/step1", callback);
    }
  },
  ////////////////////////////////////////////
  //App
  ////////////////////////////////////////////
  Activity: {
    Firstpay: function (req, res, callback) {
      res.locals.Title = "首冲活动!";
      res.render("activity/2016/firstpay", callback);
    },
    FirstpayMobile: function (req, res, callback) {
      res.locals.Title = "首冲活动!";
      res.render("activity/2016/firstpay-m", callback);
    },
    Baoming: function (req, res, callback) {
      res.locals.Title = "全民秀网勇者大冲关活动报名!";
      res.render("activity/2016/baoming", callback);
    },
  },
  Mobile: {
    Login: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (_UserState.IsLogin) {
        res.redirect("pay");
        return;
      }
      res.locals.Title = "用户登录";
      res.render("login/m_login", callback);
    }
    ,
    Pay: function (req, res, callback) {
      var _UserState = StateData.Value(req, res);
      if (!_UserState.IsLogin) {
        res.redirect("login");
        return;
      }
      res.locals.Title = "微信充值支付服务";
      res.render("pay/m_index", callback);
    }
  },
  Ads: {
    Intro: function (req, res, callback) {
      res.locals.Title = "全民秀网-美女艺人";
      res.render("activity/ad/ad-1219", callback);
    }
  },
  ////////////////////////////////////////////
  //Game专题
  ////////////////////////////////////////////
  Game: {
    Lottery: function (req, res, callback) {
      res.render("activity/2016/game/lottery", callback);
    }
  },
  ////////////////////////////////////////////
  //活动专题
  ////////////////////////////////////////////
  Zt: {
    Yongzhedachongguan: function (req, res, callback) {
      res.render("activity/2016/zt/yzdcg", callback);
    },
    Shitingzheng: function (req, res, callback) {
      res.render("activity/2016/zt/stz", callback);
    },
    ZhengJing: function (req, res, callback) {
      res.render("activity/2016/zt/zjnn", callback);
    }

  },
  ////////////////////////////////////////////
  //直播证书
  ////////////////////////////////////////////
  Cert: {
    Ycxk: function (req, res, callback) {
      res.render("help/cert/ycxk", callback);
    },
    Dxxx: function (req, res, callback) {
      res.render("help/cert/dxxx", callback);
    },
    Gbds: function (req, res, callback) {
      res.render("help/cert/gbds", callback);
    },
    Wlwh: function (req, res, callback) {
      res.render("help/cert/wlwh", callback);
    }
  },
  Modal: {
    BuyGuard: function (req, res) {
      res.render("room/guard");
    }
  },
  Report: {
    Room: function (req, res, callback) {
      var _PageData = {
        flag: 0,
        message: ""
      };
      res.locals.Title = "举报艺人";
      res.render("room/report2", callback);
    }
  },
  MobileIndex: function (req, res, callback) {
    res.locals.Title = "全民秀网-美女视频-互动娱乐平台";
    res.render("master/qmxzb", callback);
  }
};